const gulp = require('gulp');
const rename = require('gulp-rename');
const sass = require('gulp-sass');

const tsc = require('gulp-typescript');
const tsProject = tsc.createProject("tsconfig.json");

const { src, dest, watch, series } = gulp;
function buildSass() {
    return src("./src/**/*.scss", { "base": '' })
        .pipe(sass({ outputStyle: 'expanded' }).on('error', sass.logError))
        .pipe(rename({
            extname: ".wxss"
        }))
        .pipe(dest('src'))
}

function buildTs() {
    return tsProject.src()
        .pipe(tsProject())
        .js.pipe(gulp.dest("src"))
}

const tasks = series(buildSass, buildTs);

// watch('src/*.js', { events: 'all' }, function (cb) {
//     console.log(111);
//     build();
// });
watch(['./src/**/*.scss'], buildSass);
watch(['./src/**/*.ts'], buildTs);

exports.default = tasks;